package com.clear.honghefinance.admin.controller;

import com.clear.honghefinance.biz.modules.currency.domain.dto.CreateCurrencyConfigDTO;
import com.clear.honghefinance.biz.modules.currency.domain.dto.DeleteCurrencyConfigDTO;
import com.clear.honghefinance.biz.modules.currency.domain.dto.UpdateCurrencyConfigDTO;
import com.clear.honghefinance.biz.modules.currency.domain.dto.UpdateCurrencyConfigStateDTO;
import com.clear.honghefinance.biz.modules.currency.domain.vo.ListCurrencyConfigVO;
import com.clear.honghefinance.biz.modules.currency.domain.vo.GetCurrencyConfigDetailVO;
import com.clear.honghefinance.biz.modules.currency.service.ICurrencyConfigService;
import com.clear.honghefinance.common.dto.entity.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 币别设置控制器
 */
@Api(tags = "币别管理模块")
@RestController
@RequestMapping("/currencyConfig")
@Slf4j
@RequiredArgsConstructor
public class CurrencyConfigController {

    private final ICurrencyConfigService currencyConfigService;

    @ApiOperation(value = "添加币别")
    @PostMapping(value = "/create")
    public ApiResponse<Boolean> create(@Validated @RequestBody CreateCurrencyConfigDTO dto) {
        return ApiResponse.success(currencyConfigService.create(dto));
    }

    @ApiOperation(value = "删除币别")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> delete(@Validated @RequestBody DeleteCurrencyConfigDTO dto) {
        return ApiResponse.success(currencyConfigService.delete(dto));
    }

    @ApiOperation(value = "修改币别")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateCurrencyConfigDTO dto) {
        return ApiResponse.success(currencyConfigService.update(dto));
    }

    /**
     * 禁用启用币别
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "禁用启用币别")
    @PostMapping(value = "/disable")
    public ApiResponse<Boolean> disable(@Validated @RequestBody UpdateCurrencyConfigStateDTO dto) {
        return ApiResponse.success(currencyConfigService.updateDisable(dto));
    }
    @ApiOperation(value = "获取币别详情")
    @GetMapping(value = "/get")
    public ApiResponse<GetCurrencyConfigDetailVO> get(@Validated @RequestParam @NotNull(message = "币别id不能为空") @Range(min = 1) Long id) {
        return ApiResponse.success(currencyConfigService.getDetailById(id));
    }

    @ApiOperation(value = "查询币别列表")
    @GetMapping(value = "/list")
    public ApiResponse<List<ListCurrencyConfigVO>> list() {
        return ApiResponse.success(currencyConfigService.listAll());
    }

}
